package com.tanhua.server.controller;

import com.tanhua.model.vo.VoiceVO;
import com.tanhua.server.service.VoiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/peachblossom")
public class VoiceController {

    @Autowired
    private VoiceService voiceService;

    /*
     * 发送语音
     * */
    @PostMapping
    public ResponseEntity sendVoice(MultipartFile soundFile) throws Exception {
       Boolean flag =  voiceService.sendVoice(soundFile);
       if(flag){
           return ResponseEntity.ok(null);
       }
       return ResponseEntity.status(506).body("不好意思,一天最多只能上传十条");
    }

    /*
     * 接收语音
     * */
    @GetMapping
    public ResponseEntity getVoice(){
      VoiceVO vo =  voiceService.findVoice();
      if(vo == null){
          return ResponseEntity.status(506).body("今日次数已用完");
      }
      return ResponseEntity.ok(vo);
    }
}
